/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  StatusBar,
  Navigator,
  Text,
  BackAndroid,
  Image,
  View
} from 'react-native';

import Splash from './pages/Splash'; 
import { naviGoBack } from './util/CommonUtil';

let tempNavigator;
let isRemoved = false;
export default class App extends Component {
	static _configureScene() {
    return Navigator.SceneConfigs.PushFromRight;
  }

  goBack() { 
    return naviGoBack(tempNavigator);
  }

  _renderScene(route, navigator) {
    const Component = route.component;
    tempNavigator = navigator;
    if (route.name === 'Root') {
      BackAndroid.removeEventListener('hardwareBackPress', this.goBack);
      isRemoved = true;
    } else if (isRemoved) {
      
      BackAndroid.addEventListener('hardwareBackPress', this.goBack);
    }
    return (
      <Component navigator={navigator}  {...route.params} />
    );
  }

	constructor(props) {
		super(props);  
		 
	}
  render() {
    return (
      <View style={{ flex: 1 }}>
        <StatusBar
          backgroundColor="#3e9ce9"
          barStyle="light-content"
        />
        <Navigator
          style={styles.navigator}
          configureScene={this._configureScene}
          renderScene={this._renderScene.bind(this)}
          initialRoute={{
            component: Splash,
            name: 'Splash'
          }}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
	navigator: {
    flex: 1
  },
  container: {
    flex: 1,  
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
  image: {
  	height: 30,
  	width: 30,

  },
});

 
